#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

int Min(int a, int b, int c)
{
    int min = a;
    if (b < min)
        min = b;
    if (c < min)
        min = c;
    return min;
}

int findMin(int* nums, int numsSize)
{
    int mid = (numsSize) / 2;
    int left = 0;
    int right = numsSize - 1;
    int min = Min(nums[left], nums[mid], nums[right]);
    if (numsSize > 2)
    {
        while (left < right)
        {
            if (min == nums[mid] && nums[mid] != nums[right] && nums[mid] != nums[left] && nums[left] != nums[right])
            {
                if (nums[mid - 1] < nums[mid])
                {
                    right = mid;
                    mid = left + (right - left) / 2;
                    min = Min(nums[left], nums[mid], nums[right]);
                }
                else
                    break;
            }
            else if (min == nums[left] && nums[mid] != nums[right] && nums[mid] != nums[left] && nums[left] != nums[right])
            {
                break;
            }
            else if (min == nums[right] && nums[mid] != nums[right] && nums[mid] != nums[left] && nums[left] != nums[right])
            {
                left = mid;
                mid = left + (right - left) / 2;
                min = Min(nums[left], nums[mid], nums[right]);
            }
            else
            {
                break;
            }
        }
    }
    return min;
}

int main()
{
    int arr[] = { 2,3,1 };
    int i = findMin(arr, sizeof(arr)/4);
    printf("%d", i);
    return 0;
}